﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLToolkit.Data;

namespace MvcVietAir.Models
{
    public class RepositoryContacts
    {
        private DbManager db = new DbManager("MvcVietAirConnectionString");

        public List<Contact> GetAll()
        {
            using (db)
            {
                return db.SetSpCommand("Contact_All").ExecuteList<Contact>();
            }
        }
        public List<Contact> FindByName(string name)
        { 
            using(db)
            {
                return db.SetSpCommand("Contact_FindByName", db.Parameter("@Name", name)).ExecuteList<Contact>();
            }
        }
        public Contact Single(string id)
        {
            using (db)
            {
                return db.SetSpCommand("Contact_Single", db.Parameter("@Id", ChangDataType.String2Int(id))).ExecuteObject<Contact>();
            }
        }
        public int Create(Contact ct)
        {
            using (db)
            {
                return db.SetSpCommand("Contact_Create", db.CreateParameters(ct)).ExecuteNonQuery();
            }
        }
        public int Delete(string id)
        {
            using (db)
            {
                return db.SetSpCommand("Contact_Delete", db.Parameter("@Id", ChangDataType.String2Int(id))).ExecuteNonQuery();
            }
        }
    }
}